package com.ybxx.hr.action;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;

import com.ybxx.core.command.QueryFilter;
import com.ybxx.core.util.UUIDGenerator;
import com.ybxx.core.web.action.BaseAction;
import com.ybxx.hr.model.WorkContent;
import com.ybxx.hr.service.WorkContentService;

public class WorkContentAction extends BaseAction {
	@Resource
	private WorkContentService workContentService;
	private WorkContent workContent;
	private List<WorkContent> workContents;
	private String msg="succ";
	/*删除*/
	public String remove(){
		try{
			workContentService.remove(workContent.getWcid());
		}catch(Exception ex){
			msg="岗位删除失败";
		}finally{
			return "succ";
		}
	}
	/*加载查看时候需要展示的数据*/
	public String view(){
		if(workContent!=null && StringUtils.isNotEmpty(workContent.getWcid())){
			workContent=workContentService.get(workContent.getWcid());
		}
		return "view";
	}
	public String queryPage(){
		QueryFilter filter=new QueryFilter(getRequest());
		workContents=workContentService.queryPage(workContent,filter);
		super.setRownum(filter.getPagingBean().getTotalItems());
		super.setCurrentpage(Integer.parseInt(filter.getPagingBean().getStart()+"")/Integer.parseInt(filter.getPagingBean().getPageSize()+"")+1);
		super.setPageSize(Integer.parseInt(filter.getPagingBean().getPageSize()+""));
		return "queryPage";
	}
	/*保存新增，修改信息*/
	public String save(){
		if(StringUtils.isEmpty(workContent.getWcid())){
			workContent.setWcid(UUIDGenerator.getUUID());
		}
		try{
			workContentService.save(workContent);
		}catch(Exception ex){
			msg="岗位信息保存失败.";
		}finally{
			return "succ";
		}
	}
	/*加载修改时候需要展示的数据*/
	public String load(){
		if(workContent!=null && StringUtils.isNotEmpty(workContent.getWcid())){
			workContent=workContentService.get(workContent.getWcid());
		}
		return "load";
	}
	public WorkContent getWorkContent() {
		return workContent;
	}
	public void setWorkContent(WorkContent workContent) {
		this.workContent = workContent;
	}
	public List<WorkContent> getWorkContents() {
		return workContents;
	}
	public void setWorkContents(List<WorkContent> workContents) {
		this.workContents = workContents;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	
}
